<?php

namespace App\Console\Commands;

use App\Models\User;
use Illuminate\Console\Command;

class Vip extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'vip';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command description';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        $yesterday = date("Y-m-d",strtotime("-1 day"));
        User::where('vip_expired_at', $yesterday)->where('is_vip', 1)->chunk(50, function ($list) {
            foreach ($list as $model) {
                $model->is_vip = 0;
                $model->save();
            }
        });
    }
}
